home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / packet / p_aa4re / bb212src / bbsrt23d.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1990-04-07  |  11.1 KB  |  272 lines

  1. (*===========================================================================*)
  2. (* Procedure to decode incoming packets from the PK232                       *)
  3. (*                                                                           *)
  4. (*   Copyright 1988, 1989, 1990 by H. Roy Engehausen.  All rights reserved.  *)
  5. (*   This software may be freely distributed and used, but it may not        *)
  6. (*   under any circumstances be sold by anyone other than the author.        *)
  7. (*   It may be distributed by a commercial company as long as it is          *)
  8. (*   for no cost.                                                            *)
  9. (*                                                                           *)
  10. (*===========================================================================*)
  11.  
  12. PROCEDURE pk232_decode;
  13.  
  14.   VAR
  15.     i : BYTE;
  16.  
  17.   BEGIN;
  18.  
  19.     WITH active_tcb^, active_tcb^.tnc_data, pk232_buff^ DO
  20.       BEGIN;
  21.  
  22.         (*-------------------------------------------------------------------*)
  23.         (* Extract the channel and type codes                                *)
  24.         (*-------------------------------------------------------------------*)
  25.  
  26.         pk232_chan := (pk232_ctl AND $0F) + 1;
  27.         IF pk232_chan > 9 THEN
  28.           pk232_chan := 0;
  29.  
  30.         i := pk232_ctl AND $F0;
  31.  
  32.         (*-------------------------------------------------------------------*)
  33.         (* Handle a null poll response                                       *)
  34.         (*-------------------------------------------------------------------*)
  35.  
  36.         IF (pk232_ctl = pk232_incoming_cmd) AND (tnc_cmd_data > 1) THEN
  37.           BEGIN;
  38.             tnc_type   := t_to_h_ok;
  39.             pk232_len  := 0;
  40.             pk232_chan := channel;
  41.             EXIT;
  42.           END;
  43.  
  44.         (*-------------------------------------------------------------------*)
  45.         (* Handle a status response                                          *)
  46.         (*-------------------------------------------------------------------*)
  47.  
  48.         IF pk232_ctl = pk232_incoming_status THEN
  49.           BEGIN;
  50.  
  51.             pk232_chan := channel;
  52.  
  53.             (*---------------------------------------------------------------*)
  54.             (* Check for 5FXX                                                *)
  55.             (*---------------------------------------------------------------*)
  56.  
  57.             IF (pk232_dat[1] <> 'X') OR (pk232_dat[2] <> 'X') THEN
  58.               BEGIN;
  59.                 window_write_critical_i('Non XX 5F received from PK232 -- '
  60.                                                    + port_chan_s + ' -- '
  61.                                                    + pk232_dat[1]
  62.                                                    + pk232_dat[2] + ' -- ',
  63.                                          ORD(pk232_dat[3]));
  64.                 tnc_type := t_to_h_badmsg;
  65.                 EXIT;
  66.               END;
  67.  
  68.             (*---------------------------------------------------------------*)
  69.             (* Handle 5FXX                                                   *)
  70.             (*---------------------------------------------------------------*)
  71.  
  72.             IF pk232_dat[3] <> #0 THEN
  73.               tnc_type := t_to_h_badmsg
  74.             ELSE
  75.               BEGIN;
  76.                 tnc_type  := t_to_h_ok;
  77.                 pk232_len := 0;
  78.                 active_port^.port_pk232_data_ack := FALSE;
  79.  
  80. {$IFDEF DEBUG}
  81. WRITELN('5FXX0 received');
  82. {$ENDIF}
  83.  
  84.               END;
  85.  
  86.             EXIT;
  87.  
  88.           END;
  89.  
  90.         (*-------------------------------------------------------------------*)
  91.         (* Incoming monitor data                                             *)
  92.         (*-------------------------------------------------------------------*)
  93.  
  94.         IF pk232_ctl = pk232_incoming_mon THEN
  95.           BEGIN;
  96.  
  97. {$IFDEF DEBUG}
  98. WRITELN('Incoming monitor data');
  99. {$ENDIF}
  100.  
  101.             pk232_chan := 0;
  102.             tnc_type   := t_to_h_mh_noi;
  103.             EXIT;
  104.  
  105.           END;
  106.  
  107.         (*-------------------------------------------------------------------*)
  108.         (* Handle incoming data                                              *)
  109.         (*-------------------------------------------------------------------*)
  110.  
  111.         IF i = pk232_incoming_data THEN
  112.           BEGIN;
  113.             tnc_type := t_to_h_conn;
  114.             EXIT;
  115.           END;
  116.  
  117.         (*-------------------------------------------------------------------*)
  118.         (* Handle incoming link status                                       *)
  119.         (*-------------------------------------------------------------------*)
  120.  
  121.         IF i = pk232_incoming_link2 THEN
  122.           BEGIN;
  123.  
  124. {$IFDEF DEBUG}
  125. WRITELN('Link status -- ', channel, ' -- ', pk232_ctl);
  126. {$ENDIF}
  127.  
  128.             (*---------------------------------------------------------------*)
  129.             (* Clean things up                                               *)
  130.             (*---------------------------------------------------------------*)
  131.  
  132.             tnc_type := t_to_h_links;
  133.  
  134.             IF (pk232_len >= 3) AND (pk232_len < 259) THEN
  135.               pk232_ctl := pk232_len - 3
  136.             ELSE
  137.               pk232_ctl := 1;
  138.  
  139.             strip_crlf(pk232_str);
  140.  
  141.             (*---------------------------------------------------------------*)
  142.             (* Translate DISCONNECT message                                  *)
  143.             (*---------------------------------------------------------------*)
  144.  
  145.             IF subword(@pk232_str, 1, 1) = 'DISCONNECTED:' THEN
  146.               pk232_str := t_to_h_disc + subword(@pk232_str, 2, 0);
  147.  
  148.             (*---------------------------------------------------------------*)
  149.             (* Set length and done                                           *)
  150.             (*---------------------------------------------------------------*)
  151.  
  152.             pk232_len := LENGTH(pk232_str);
  153.             IF pk232_len <= 252 THEN
  154.               INC(pk232_len, 3);
  155.  
  156.             EXIT;
  157.           END;
  158.  
  159.         (*-------------------------------------------------------------------*)
  160.         (* All that should be left by now is command responses               *)
  161.         (*-------------------------------------------------------------------*)
  162.  
  163.         IF (pk232_ctl <> pk232_incoming_cmd) AND
  164.                                              ((i <> $40) AND NOT l_switch) THEN
  165.           window_write_critical_i('Didn''t handle PK232 Response -- '
  166.                                                         + port_chan_s + ' -- ',
  167.                                    pk232_ctl);
  168.  
  169.         pk232_chan := channel;
  170.  
  171.         (*-------------------------------------------------------------------*)
  172.         (* If we sent a command then we must interpret the responses         *)
  173.         (*-------------------------------------------------------------------*)
  174.  
  175.         IF tnc_cmd_data = info_cmd_cmd THEN
  176.  
  177.           IF pk232_dat[3] >= #$20 THEN      (* More than $20 indicates a     *)
  178.             BEGIN;                          (* parameter response            *)
  179.               tnc_type := t_to_h_okmsg;
  180.               IF l_switch THEN
  181.                 BEGIN;
  182.  
  183.                   (*---------------------------------------------------------*)
  184.                   (*  L response -- DED format is:                           *)
  185.                   (*      Word 1 -- Number of link status messages waiting   *)
  186.                   (*      Word 2 -- Number of data packets waiting           *)
  187.                   (*      Word 3 -- Number of packets awaiting 1st trans     *)
  188.                   (*      Word 4 -- Number of frames send at least once      *)
  189.                   (*      Word 5 -- Number of retries                        *)
  190.                   (*      Word 6 -- Link status #                            *)
  191.                   (*---------------------------------------------------------*)
  192.  
  193.                   l_str     := '0 0 0 0 0 0' + etb;
  194.                              (* 12345678901 *)
  195.                   l_str[5]  := pk232_dat[5];
  196.                   l_str[7]  := pk232_dat[5];
  197.                   l_str[9]  := pk232_dat[6];
  198.                   l_str[11] := pk232_dat[3];
  199.                   pk232_str := l_str;
  200.                   pk232_len := LENGTH(pk232_str) + 3;
  201.  
  202.                 END;
  203.               EXIT;
  204.  
  205.             END
  206.           ELSE
  207.             IF pk232_dat[3] = #0 THEN       (* 0 = AOK!                      *)
  208.               BEGIN;
  209.                 tnc_type  := t_to_h_ok;
  210.                 pk232_len := 0;
  211.                 EXIT;
  212.               END
  213.             ELSE
  214.               BEGIN;
  215.  
  216.                 (*-----------------------------------------------------------*)
  217.                 (*  Translate response to characters                         *)
  218.                 (*-----------------------------------------------------------*)
  219.  
  220.                 tnc_type := t_to_h_badmsg;  (* All others are bad news.      *)
  221.                 CASE ORD(pk232_dat[3]) OF   (* Interpret the error code      *)
  222.                   $00 : pk232_str := '';
  223.                   $01 : pk232_str := 'Bad';
  224.                   $02 : pk232_str := 'Too many';
  225.                   $03 : pk232_str := 'Not enough';
  226.                   $04 : pk232_str := 'Too long';
  227.                   $05 : pk232_str := 'Range';
  228.                   $06 : pk232_str := 'Callsign';
  229.                   $07 : pk232_str := 'Unknown command';
  230.                   $08 : pk232_str := 'Need VIA';
  231.                   $09 : pk232_str := 'Not while connected';
  232.                   $0A : pk232_str := 'Need MYCALL';
  233.                   $0B : pk232_str := 'Need MYSELCAL';
  234.                   $0C : pk232_str := 'Already connected';
  235.                   $0D : pk232_str := 'Not while disconnected';
  236.                   $0E : pk232_str := 'Different connectees';
  237.                   $0F : pk232_str := 'Too many packets outstanding';
  238.                   $10 : pk232_str := 'Clock not set';
  239.                   $11 : pk232_str := 'Need ALL/NONE/YES/NO';
  240.                   $15 : pk232_str := 'Not in this mode';
  241.                   ELSE
  242.                     BEGIN;
  243.                       window_write_critical_i(
  244.                                           'PK232 Invalid command response -- '
  245.                                                         + port_chan_s + ' -- ',
  246.                                           ORD(pk232_dat[3]));
  247.                       pk232_str := 'Invalid command response';
  248.                     END;
  249.                 END;
  250.  
  251.                 pk232_len := LENGTH(pk232_str) + 3;
  252.                 EXIT;
  253.  
  254.               END;
  255.  
  256.         (*-------------------------------------------------------------------*)
  257.         (* Bit bucket                                                        *)
  258.         (*-------------------------------------------------------------------*)
  259.  
  260.         window_write_critical_i('Non interpreted response received from PK232'
  261.                                           + port_chan_s + ' -- '
  262.                                           + CHR(pk232_ctl)
  263.                                           + pk232_dat[1]
  264.                                           + pk232_dat[2],
  265.                                  ORD(pk232_dat[3]));
  266.  
  267.         tnc_type := t_to_h_badmsg;
  268.  
  269.       END;
  270.  
  271.   END;
  272.